package com.sacc.service.Impl;

import com.power.common.model.CommonResult;
import com.sacc.mapper.OriginDetailMapper;
import com.sacc.pojo.OriginDetail;
import com.sacc.service.OriginDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 滚~韬
 * @date 2022/5/7 15:41
 */

@Service
public class OriginDetailServiceImpl implements OriginDetailService {
    @Autowired
    private OriginDetailMapper originDetailMapper;

    /**
     * 插入或者更新信息
     * @param originDetail
     * @return
     */
    @Override
    public CommonResult AddOriginDetail(OriginDetail originDetail) {
        try{
            if(originDetailMapper.selectById(originDetail.getProductOriginId())!=null){
                originDetailMapper.updateById(originDetail);
                return new CommonResult(true,"更新成功:",originDetail);
            }else {
                originDetailMapper.insert(originDetail);
                return new CommonResult(true,"插入成功:",originDetail);
            }
        }catch (Exception e){
            return new CommonResult(false,"插入失败:",originDetail);
        }
    }

    /**
     * 删除信息
     * @param productOriginId
     * @return
     */
    @Override
    public CommonResult DeleteOriginDetail(Integer productOriginId) {
        try{
            if(originDetailMapper.selectById(productOriginId)!=null){
                originDetailMapper.deleteById(productOriginId);
                return new CommonResult(true,"删除成功",productOriginId);
            }else {
                return new CommonResult(true,"没有该originDetail");
            }
        }catch (Exception e){
            return new CommonResult(false,"删除失败",productOriginId);
        }
    }

    /**
     * 得到源信息
     * @param productOriginId
     * @return
     */
    @Override
    public OriginDetail GetOriginDetail(Integer productOriginId) {
        return originDetailMapper.selectById(productOriginId);
    }
}
